package zhieasy.cn.xpu_helper.controller.found;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zhieasy.cn.common.vo.ResultVO;
import zhieasy.cn.model.found.LafCategory;
import zhieasy.cn.model.found.LostAndFind;
import zhieasy.cn.service.found.LafService;

import java.util.UUID;

/**
 * @author wangzeya
 * @create 2020-08-02 21:30:00
 */
@Api(tags = "失物招领模块，通用接口")
@RequestMapping("/found")
@RestController
@ApiImplicitParams({
        @ApiImplicitParam(name="pageNum",value ="当前页码",required =true,paramType="form",dataType="int"),
        @ApiImplicitParam(name="pageSize",value ="页面大小",required =true,paramType="form",dataType="int"),
        @ApiImplicitParam(name="lafType",value ="失物招领类型",required =true,paramType="form",dataType="int"),
        @ApiImplicitParam(name="lafCtgId",value ="失物分类id",required =true,paramType="form",dataType="int")
})
public class LafController {
    @Autowired
    private LafService lafService;

    /**
     * 获取分类列表
     */
    @ApiOperation(value = "获取分类列表", notes = "获取分类列表")
    @GetMapping(value = "/category", produces = "application/json;charset=UTF-8")
    public ResultVO<LafCategory> findAllCategory(){
        //查询到所有分类
        return  lafService.findAllCategory();
    }

    @ApiOperation(value = "获取分类列表", notes = "获取分类列表")
    @PostMapping(value = "/category/test", produces = "application/json;charset=UTF-8")
    public ResultVO<LafCategory> findAllCategoryTest(){
        //查询到所有分类
        return  lafService.findAllCategory();
    }

    /**
     * 发布失物招领
     */
    @ApiOperation(value = "发布失物招领", notes = "发布失物招领")
    @PostMapping(value = "/lostAndFound", produces = "application/json;charset=UTF-8")
    public ResultVO createLaf(@ApiParam(value = "lostAndFound对象")@RequestBody LostAndFind lostAndFind){
        lostAndFind.setLafActive(0);
        lostAndFind.setId(UUID.randomUUID().toString());
        lostAndFind.setLafCreateTime(System.currentTimeMillis());
        //调用service创建
        return lafService.creatLaf(lostAndFind);
    }




    /**
     * 查看失物招领详细信息
     */
    @ApiOperation(value = "查看失物招领详细信息", notes = "查看失物招领详细信息")
    @GetMapping(value = "/lostAndFound/{lafId}", produces = "application/json;charset=UTF-8")
    public ResultVO<LostAndFind> findLafDetail(@ApiParam("帖子id")@PathVariable("lafId") String lafId){
        return lafService.findLafDetail(lafId);
    }

    /**
     * 查询所有失物招领列表
     */
    @ApiOperation(value = "查询所有失物招领列表", notes = "查询所有失物招领列表")
    @GetMapping(value = "/lostAndFound/type/{type}/category/{lafCtgId}", produces = "application/json;charset=UTF-8")
    public ResultVO<IPage<LostAndFind>> findAllLafListByType(
        @ApiParam("丢失还是捡取,1->丢失,2->捡取")@PathVariable("type") int type,
        @ApiParam("要什么分类，例如所有、钥匙这种")@RequestParam(value = "lafCtgId")int lafCtgId,
        @ApiParam("页数")@RequestParam("pageIndex")int pageIndex,
        @ApiParam("每页要多少数据")@RequestParam("pageSize")int pageSize
        ){
        return lafService.findLafList(pageIndex, pageSize, type, lafCtgId);
    }

    /**
     * 搜索失物招领
     */
    @ApiOperation(value = "搜索失物招领", notes = "搜索失物招领")
    @GetMapping(value = "/lostAndFound/lafName/{lafName}", produces = "application/json;charset=UTF-8")
    public ResultVO<IPage<LostAndFind>> findLafByName(@ApiParam("页数")@RequestParam("pageIndex")int pageIndex,
                                                      @ApiParam("每页要多少数据")@RequestParam("pageSize")int pageSize,
                                                      @ApiParam("物品名称")@PathVariable("lafName")String lafName){
        return lafService.findLafByLafName(pageIndex, pageSize, lafName);
    }

}
